2016-11-04 20:44:38 +00:00
|
|
|
package service
|
|
|
|
|
|
|
|
import (
|
2017-03-15 15:55:30 +00:00
|
|
|
"context"
|
2016-11-04 20:44:38 +00:00
|
|
|
"testing"
|
|
|
|
|
2017-06-22 19:50:45 +00:00
|
|
|
"github.com/kolide/fleet/server/config"
|
|
|
|
"github.com/kolide/fleet/server/datastore/inmem"
|
|
|
|
"github.com/kolide/fleet/server/kolide"
|
2016-11-04 20:44:38 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
2017-03-22 19:40:01 +00:00
|
|
|
func TestCleanupURL(t *testing.T) {
|
|
|
|
tests := []struct {
|
|
|
|
in string
|
|
|
|
expected string
|
|
|
|
name string
|
|
|
|
}{
|
|
|
|
{" http://foo.bar.com ", "http://foo.bar.com", "leading and trailing whitespace"},
|
|
|
|
{"\n http://foo.com \t", "http://foo.com", "whitespace"},
|
|
|
|
{"http://foo.com", "http://foo.com", "noop"},
|
|
|
|
{"http://foo.com/", "http://foo.com", "trailing slash"},
|
|
|
|
}
|
|
|
|
for _, test := range tests {
|
|
|
|
t.Run(test.name, func(tt *testing.T) {
|
|
|
|
actual := cleanupURL(test.in)
|
|
|
|
assert.Equal(tt, test.expected, actual)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-11-09 17:19:07 +00:00
|
|
|
func TestCreateAppConfig(t *testing.T) {
|
2016-11-25 18:08:22 +00:00
|
|
|
ds, err := inmem.New(config.TestConfig())
|
2016-11-04 20:44:38 +00:00
|
|
|
require.Nil(t, err)
|
2017-01-05 17:27:56 +00:00
|
|
|
require.Nil(t, ds.MigrateData())
|
|
|
|
|
2016-11-14 18:22:54 +00:00
|
|
|
svc, err := newTestService(ds, nil)
|
2016-11-04 20:44:38 +00:00
|
|
|
require.Nil(t, err)
|
2016-11-09 17:19:07 +00:00
|
|
|
var appConfigTests = []struct {
|
|
|
|
configPayload kolide.AppConfigPayload
|
2016-11-04 20:44:38 +00:00
|
|
|
}{
|
|
|
|
{
|
2016-11-09 17:19:07 +00:00
|
|
|
configPayload: kolide.AppConfigPayload{
|
2016-11-04 20:44:38 +00:00
|
|
|
OrgInfo: &kolide.OrgInfo{
|
|
|
|
OrgLogoURL: stringPtr("acme.co/images/logo.png"),
|
|
|
|
OrgName: stringPtr("Acme"),
|
|
|
|
},
|
|
|
|
ServerSettings: &kolide.ServerSettings{
|
|
|
|
KolideServerURL: stringPtr("https://acme.co:8080/"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2016-11-09 17:19:07 +00:00
|
|
|
for _, tt := range appConfigTests {
|
|
|
|
result, err := svc.NewAppConfig(context.Background(), tt.configPayload)
|
2016-11-04 20:44:38 +00:00
|
|
|
require.Nil(t, err)
|
|
|
|
|
2016-11-09 17:19:07 +00:00
|
|
|
payload := tt.configPayload
|
2016-11-04 20:44:38 +00:00
|
|
|
assert.NotEmpty(t, result.ID)
|
|
|
|
assert.Equal(t, *payload.OrgInfo.OrgLogoURL, result.OrgLogoURL)
|
|
|
|
assert.Equal(t, *payload.OrgInfo.OrgName, result.OrgName)
|
2017-03-22 19:40:01 +00:00
|
|
|
assert.Equal(t, "https://acme.co:8080", result.KolideServerURL)
|
2016-11-04 20:44:38 +00:00
|
|
|
}
|
|
|
|
}
|