소스 검색

Update comments, update unit tests

Signed-off-by: Sean Holcomb <seanholcomb@gmail.com>
Sean Holcomb 2 년 전
부모
커밋
55bc0f578d
2개의 변경된 파일47개의 추가작업 그리고 60개의 파일을 삭제
  1. 9 7
      pkg/cloud/config/controller.go
  2. 38 53
      pkg/cloud/config/controller_test.go

+ 9 - 7
pkg/cloud/config/controller.go

@@ -284,16 +284,22 @@ func (c *Controller) DisableConfig(key, sourceStr string) error {
 	return nil
 }
 
-// DeleteConfig removes an config from the statuses and deletes the config on all observers if it was active
-func (c *Controller) DeleteConfig(key, source string) error {
+// DeleteConfig removes a config from the statuses and deletes the config on all observers if it was active
+// This can only be used on configs with ConfigControllerSource
+func (c *Controller) DeleteConfig(key, sourceStr string) error {
 	c.lock.Lock()
 	defer c.lock.Unlock()
+	source := GetConfigSource(sourceStr)
+	if source != ConfigControllerSource {
+		return fmt.Errorf("controller does not own config with key %s from source %s, manage this config at its source", key, source.String())
+	}
+
 	statuses, err := c.load()
 	if err != nil {
 		return fmt.Errorf("failed to load statuses")
 	}
 
-	err = c.deleteConfig(key, GetConfigSource(source), statuses)
+	err = c.deleteConfig(key, source, statuses)
 	if err != nil {
 		return fmt.Errorf("Controller: DeleteConfig: %w", err)
 	}
@@ -301,10 +307,6 @@ func (c *Controller) DeleteConfig(key, source string) error {
 }
 
 func (c *Controller) deleteConfig(key string, source ConfigSource, statuses Statuses) error {
-	if source != ConfigControllerSource {
-		return fmt.Errorf("controller does not own config with key %s from source %s, manage this config at its source", key, source.String())
-	}
-
 	is, ok := statuses.Get(key, source)
 	if !ok {
 		return fmt.Errorf("config with key %s from source %s does not exist", key, source.String())

+ 38 - 53
pkg/cloud/config/controller_test.go

@@ -185,14 +185,6 @@ func TestIntegrationController_pullWatchers(t *testing.T) {
 				},
 			},
 			expectedStatuses: []*Status{
-				{
-					Source:     HelmSource,
-					Key:        validAthenaConf.Key(),
-					Active:     false, // this value changed
-					Valid:      true,
-					ConfigType: AthenaConfigType,
-					Config:     validAthenaConf,
-				},
 				{
 					Source:     HelmSource,
 					Key:        validBigQueryConf.Key(),
@@ -330,14 +322,6 @@ func TestIntegrationController_pullWatchers(t *testing.T) {
 				},
 			},
 			expectedStatuses: []*Status{
-				{
-					Source:     ConfigFileSource,
-					Key:        validAthenaConf.Key(),
-					Active:     false, // this value changed
-					Valid:      true,
-					ConfigType: AthenaConfigType,
-					Config:     validAthenaConf,
-				},
 				{
 					Source:     ConfigFileSource,
 					Key:        validBigQueryConf.Key(),
@@ -477,21 +461,29 @@ func TestIntegrationController_pullWatchers(t *testing.T) {
 			expectedStatuses: []*Status{
 				{
 					Source:     MultiCloudSource,
-					Key:        validAthenaConf.Key(),
+					Key:        validBigQueryConf.Key(),
 					Active:     true,
 					Valid:      true,
-					ConfigType: AthenaConfigType,
-					Config:     validAthenaConf,
+					ConfigType: BigQueryConfigType,
+					Config:     validBigQueryConf,
 				},
+			},
+		},
+		"Multi Cloud Delete All": {
+			initialStatuses: []*Status{
 				{
 					Source:     MultiCloudSource,
-					Key:        validBigQueryConf.Key(),
+					Key:        validAthenaConf.Key(),
 					Active:     true,
 					Valid:      true,
-					ConfigType: BigQueryConfigType,
-					Config:     validBigQueryConf,
+					ConfigType: AthenaConfigType,
+					Config:     validAthenaConf,
 				},
 			},
+			configWatchers: map[ConfigSource]cloudconfig.KeyedConfigWatcher{
+				MultiCloudSource: &MockKeyedConfigWatcher{},
+			},
+			expectedStatuses: []*Status{},
 		},
 		// Watch Interaction
 		"New Helm, Existing Config File": {
@@ -722,14 +714,6 @@ func TestIntegrationController_pullWatchers(t *testing.T) {
 		},
 		"Update Config File, Existing Helm": {
 			initialStatuses: []*Status{
-				{
-					Source:     ConfigFileSource,
-					Key:        validAthenaConf.Key(),
-					Active:     false,
-					Valid:      true,
-					ConfigType: AthenaConfigType,
-					Config:     validAthenaConf,
-				},
 				{
 					Source:     HelmSource,
 					Key:        validBigQueryConf.Key(),
@@ -758,14 +742,6 @@ func TestIntegrationController_pullWatchers(t *testing.T) {
 					ConfigType: AthenaConfigType,
 					Config:     validAthenaConfModifiedProperty,
 				},
-				{
-					Source:     HelmSource,
-					Key:        validBigQueryConf.Key(),
-					Active:     false,
-					Valid:      true,
-					ConfigType: BigQueryConfigType,
-					Config:     validBigQueryConf,
-				},
 			},
 		},
 		"New Config File Invalid, Existing Helm": {
@@ -1037,13 +1013,6 @@ func TestIntegrationController_EnableConfig(t *testing.T) {
 			inputSource: ConfigControllerSource.String(),
 			expectErr:   true,
 		},
-		"invalid source": {
-			initial:     []*Status{},
-			expected:    []*Status{},
-			inputKey:    validAthenaConf.Key(),
-			inputSource: MultiCloudSource.String(),
-			expectErr:   true,
-		},
 		"config is already enabled": {
 			initial: []*Status{
 				makeStatus(validAthenaConf, true, ConfigControllerSource),
@@ -1055,6 +1024,17 @@ func TestIntegrationController_EnableConfig(t *testing.T) {
 			inputSource: ConfigControllerSource.String(),
 			expectErr:   true,
 		},
+		"alternate source": {
+			initial: []*Status{
+				makeStatus(validAthenaConf, false, MultiCloudSource),
+			},
+			expected: []*Status{
+				makeStatus(validAthenaConf, true, MultiCloudSource),
+			},
+			inputKey:    validAthenaConf.Key(),
+			inputSource: MultiCloudSource.String(),
+			expectErr:   false,
+		},
 		"enabled disabled single config": {
 			initial: []*Status{
 				makeStatus(validAthenaConf, false, ConfigControllerSource),
@@ -1146,13 +1126,7 @@ func TestIntegrationController_DisableConfig(t *testing.T) {
 			inputSource: ConfigControllerSource.String(),
 			expectErr:   true,
 		},
-		"invalid source": {
-			initial:     []*Status{},
-			expected:    []*Status{},
-			inputKey:    validAthenaConf.Key(),
-			inputSource: MultiCloudSource.String(),
-			expectErr:   true,
-		},
+
 		"config is already disabled": {
 			initial: []*Status{
 				makeStatus(validAthenaConf, false, ConfigControllerSource),
@@ -1177,6 +1151,17 @@ func TestIntegrationController_DisableConfig(t *testing.T) {
 			inputSource: ConfigControllerSource.String(),
 			expectErr:   false,
 		},
+		"alternate source": {
+			initial: []*Status{
+				makeStatus(validAthenaConf, true, MultiCloudSource),
+			},
+			expected: []*Status{
+				makeStatus(validAthenaConf, false, MultiCloudSource),
+			},
+			inputKey:    validAthenaConf.Key(),
+			inputSource: MultiCloudSource.String(),
+			expectErr:   false,
+		},
 		"disable config, matching config from separate source": {
 			initial: []*Status{
 				makeStatus(validAthenaConf, true, ConfigControllerSource),
@@ -1369,7 +1354,7 @@ func buildStatuses(statusList []*Status) (Statuses, error) {
 
 func checkStatuses(actual, expected Statuses) error {
 	if len(actual.List()) != len(expected.List()) {
-		return fmt.Errorf("integration statueses did not have the correct length actaul: %d, expected: %d", len(actual), len(expected))
+		return fmt.Errorf("integration statueses did not have the correct length actaul: %d, expected: %d", len(actual.List()), len(expected.List()))
 	}
 
 	for _, actualStatus := range actual.List() {