netmaker/ee/license_test.go
Gabriel de Souza Seibel de146321f0
[NET-477] Pick AMB URL dynamically (#2489)
* Introduce config for environment

* Introduce func to get environment

* Choose accounts api host from environment

* Test the ee package on workflows

* Use build tag ee for license_test.go
2023-08-08 15:59:38 +05:30

77 lines
1.5 KiB
Go

//go:build ee
// +build ee
package ee
import (
"github.com/gravitl/netmaker/config"
"testing"
)
func Test_getAccountsHost(t *testing.T) {
tests := []struct {
name string
envK string
envV string
conf string
want string
}{
{
name: "no env var and no conf",
envK: "NOT_THE_CORRECT_ENV_VAR",
envV: "dev",
want: "https://api.accounts.netmaker.io",
},
{
name: "dev env var",
envK: "ENVIRONMENT",
envV: "dev",
want: "https://api.dev.accounts.netmaker.io",
},
{
name: "staging env var",
envK: "ENVIRONMENT",
envV: "staging",
want: "https://api.staging.accounts.netmaker.io",
},
{
name: "prod env var",
envK: "ENVIRONMENT",
envV: "prod",
want: "https://api.accounts.netmaker.io",
},
{
name: "dev conf",
conf: "dev",
want: "https://api.dev.accounts.netmaker.io",
},
{
name: "staging conf",
conf: "staging",
want: "https://api.staging.accounts.netmaker.io",
},
{
name: "prod conf",
conf: "prod",
want: "https://api.accounts.netmaker.io",
},
{
name: "env var vs conf precedence",
envK: "ENVIRONMENT",
envV: "prod",
conf: "staging",
want: "https://api.accounts.netmaker.io",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
config.Config.Server.Environment = tt.conf
if tt.envK != "" {
t.Setenv(tt.envK, tt.envV)
}
if got := getAccountsHost(); got != tt.want {
t.Errorf("getAccountsHost() = %v, want %v", got, tt.want)
}
})
}
}