<commit_before>package sacloud

import (
	"encoding/json"
	"testing"
	"time"

	"github.com/stretchr/testify/assert"
)

var testProxyLBJSON = `

{
    "ID": 123456789012,
    "Name": "example",
    "Description": "example",
    "Settings": {
      "ProxyLB": {
        "HealthCheck": {
          "Protocol": "http",
          "Path": "/",
          "Host": "example.com",
          "DelayLoop": 10
        },
        "SorryServer": {
          "IPAddress": "172.16.58.3",
          "Port": 80
        },
        "BindPorts": [
          {
            "ProxyMode": "https",
            "Port": 443
          }
        ],
        "Servers": [
          {
            "IPAddress": "192.168.3.11",
            "Port": 443,
            "Enabled": true
          },
          {
            "IPAddress": "172.16.31.10",
            "Port": 443,
            "Enabled": true
          }
        ]
      }
    },
    "Status": {
      "FQDN": "site-xxxxxxx.proxylbN.sakura.ne.jp",
      "ProxyNetworks": [
        "172.16.58.3/28"
      ],
      "UseVIPFailover": true
    },
    "ServiceClass": "cloud/proxylb/plain/1000",
    "Availability": "available",
    "CreatedAt": "2019-02-28T11:15:59+09:00",
    "ModifiedAt": "2019-02-28T11:15:59+09:00",
    "Provider": {
      "ID": 9100001,
      "Class": "proxylb",
      "Name": "proxylb1",
      "ServiceClass": "cloud/proxylb"
    },
    "Tags": [
      "tag1",
      "tag2"
    ]
  }
`

var testProxyLBCertificatesJSON = `
	{
		"ServerCertificate": "dummy1",
		"IntermediateCertificate": "dummy2",
    	"PrivateKey": "dummy3",
    	"CertificateEndDate": "May  4 01:37:47 2019 GMT"
	}
`

func TestMarshalProxyLBJSON(t *testing.T) {
	var proxyLB ProxyLB
	err := json.Unmarshal([]byte(testProxyLBJSON), &proxyLB)

	assert.NoError(t, err)
	assert.NotEmpty(t, proxyLB)

	assert.NotEmpty(t, proxyLB.ID)
	assert.NotEmpty(t, proxyLB.Status.FQDN)
	assert.NotEmpty(t, proxyLB.Status.ProxyNetworks)
	assert.True(t, proxyLB.Status.UseVIPFailover)
	assert.NotEmpty(t, proxyLB.Provider.Class)
}

func TestMarshalProxyLBCertificate(t *testing.T) {
	var certs ProxyLBCertificate
	err := json.Unmarshal([]byte(testProxyLBCertificatesJSON), &certs)

	assert.NoError(t, err)
	assert.NotEmpty(t, certs)

	assert.Equal(t, "dummy1", certs.ServerCertificate)<commit_msg>Fix test JSON<commit_after>package sacloud

import (
	"encoding/json"
	"testing"
	"time"

	"github.com/stretchr/testify/assert"
)

var testProxyLBJSON = `

{
    "ID": 123456789012,
    "Name": "example",
    "Description": "example",
    "Settings": {
      "ProxyLB": {
        "HealthCheck": {
          "Protocol": "http",
          "Path": "/",
          "Host": "example.com",
          "DelayLoop": 10
        },
        "SorryServer": {
          "IPAddress": "172.16.58.3",
          "Port": 80
        },
        "BindPorts": [
          {
            "ProxyMode": "https",
            "Port": 443
          }
        ],
        "Servers": [
          {
            "IPAddress": "192.168.3.11",
            "Port": 443,
            "Enabled": true
          },
          {
            "IPAddress": "172.16.31.10",
            "Port": 443,
            "Enabled": true
          }
        ]
      }
    },
    "Status": {
      "FQDN": "site-xxxxxxx.proxylbN.sakura.ne.jp",
      "ProxyNetworks": [
        "172.16.58.3/28"
      ],
      "UseVIPFailover": true
    },
    "ServiceClass": "cloud/proxylb/plain/1000",
    "Availability": "available",
    "CreatedAt": "2019-02-28T11:15:59+09:00",
    "ModifiedAt": "2019-02-28T11:15:59+09:00",
    "Provider": {
      "ID": 9100001,
      "Class": "proxylb",
      "Name": "proxylb1",
      "ServiceClass": "cloud/proxylb"
    },
    "Tags": [
      "tag1",
      "tag2"
    ]
  }
`

var testProxyLBCertificatesJSON = `
	{
		"ServerCertificate": "dummy1",
		"IntermediateCertificate": "dummy2",
    	"PrivateKey": "dummy3",
    	"CertificateEndDate": "May  4 01:37:47 2019 GMT",
		"CertificateCommonName": ""
	}
`

func TestMarshalProxyLBJSON(t *testing.T) {
	var proxyLB ProxyLB
	err := json.Unmarshal([]byte(testProxyLBJSON), &proxyLB)

	assert.NoError(t, err)
	assert.NotEmpty(t, proxyLB)

	assert.NotEmpty(t, proxyLB.ID)
	assert.NotEmpty(t, proxyLB.Status.FQDN)
	assert.NotEmpty(t, proxyLB.Status.ProxyNetworks)
	assert.True(t, proxyLB.Status.UseVIPFailover)
	assert.NotEmpty(t, proxyLB.Provider.Class)
}

func TestMarshalProxyLBCertificate(t *testing.T) {
	var certs ProxyLBCertificate
	err := json.Unmarshal([]byte(testProxyLBCertificatesJSON), &certs)

	assert.NoError(t, err)
	assert.NotEmpty(t, certs)

	assert.Equal(t, "dummy1", certs.ServerCertificate)
{'fraction_non_alphanumeric': 0.16663050553265352, 'fraction_numerical': 0.05467563462790193, 'mean_word_length': 2.2952108649035026, 'pattern_counts': {'":': 83, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 8, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4518182', 'n_tokens_mistral': 1878, 'n_tokens_neox': 1669, 'n_words': 258}