MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / TestParseCommandLineWithConfigContent

Function TestParseCommandLineWithConfigContent

rest/config_test.go:880–956  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

878}
879
880func TestParseCommandLineWithConfigContent(t *testing.T) {
881 content := `{"logging":{"log_file_path":"/var/tmp/sglogs","console":{"log_level":"debug","log_keys":["*"]},
882 "error":{"enabled":true,"rotation":{"max_size":20,"max_age":180}},"warn":{"enabled":true,"rotation":{
883 "max_size":20,"max_age":90}},"info":{"enabled":false},"debug":{"enabled":false}},"databases":{"db1":{
884 "server":"couchbase://localhost","username":"username","password":"password","bucket":"default",
885 "certpath":"/etc/ssl/certs/cert.pem","cacertpath":"/etc/ssl/certs/ca.cert","keypath":"/etc/ssl/certs/key.pem",
886 "users":{"GUEST":{"disabled":false,"admin_channels":["*"]}},"allow_conflicts":false,"revs_limit":20}}}`
887
888 configFile, err := os.CreateTemp("", "sync_gateway.conf")
889 configFileName := configFile.Name()
890 require.NoError(t, err, "Couldn't create configuration file")
891 _, err = configFile.Write([]byte(content))
892 assert.NoError(t, err, "Writing JSON content")
893
894 defer func() {
895 assert.NoError(t, configFile.Close(), "Couldn't close file: %v ", configFileName)
896 assert.NoError(t, os.Remove(configFileName), "Couldn't remove file: %v ", configFileName)
897 assert.False(t, base.FileExists(configFileName), "File %v should be removed", configFileName)
898 }()
899
900 var (
901 adminInterface = "127.10.0.1:4985"
902 profileInterface = "127.10.0.1:8088"
903 cacertpath = "/etc/ssl/certs/ca.cert"
904 certpath = "/etc/ssl/certs/client.pem"
905 configServer = "http://127.0.0.1:4981/conf"
906 defaultLogFilePath = "/var/log/sync_gateway"
907 deploymentID = "DEPID100"
908 interfaceAddress = "4443"
909 keypath = "/etc/ssl/certs/key.pem"
910 logKeys = "Admin,Access,Auth,Bucket"
911 logFilePath = "/var/log/sync_gateway"
912 )
913 args := []string{
914 "sync_gateway",
915 "--adminInterface", adminInterface,
916 "--cacertpath", cacertpath,
917 "--certpath", certpath,
918 "--configServer", configServer,
919 "--defaultLogFilePath", defaultLogFilePath,
920 "--deploymentID", deploymentID,
921 "--interface", interfaceAddress,
922 "--keypath", keypath,
923 "--log", logKeys,
924 "--logFilePath", logFilePath,
925 "--pretty",
926 "--verbose",
927 "--profileInterface", profileInterface,
928 configFile.Name()}
929
930 config, err := ParseCommandLine(base.TestCtx(t), args, flag.ContinueOnError)
931 require.NoError(t, err, "while parsing commandline options")
932 assert.Equal(t, interfaceAddress, *config.Interface)
933 assert.Equal(t, adminInterface, *config.AdminInterface)
934 assert.Equal(t, profileInterface, *config.ProfileInterface)
935 assert.Equal(t, configServer, *config.ConfigServer)
936 assert.Equal(t, deploymentID, *config.DeploymentID)
937 assert.Equal(t, logFilePath, config.Logging.LogFilePath)

Callers

nothing calls this directly

Calls 10

FileExistsFunction · 0.92
TestCtxFunction · 0.92
SetFromArrayFunction · 0.92
ParseCommandLineFunction · 0.85
NameMethod · 0.65
CloseMethod · 0.65
RemoveMethod · 0.65
LenMethod · 0.65
WriteMethod · 0.45
EqualMethod · 0.45

Tested by

no test coverage detected