(t *testing.T)
| 133 | } |
| 134 | |
| 135 | func TestParseModuleConfig(t *testing.T) { |
| 136 | // Create a test Template |
| 137 | template := &Template{} |
| 138 | |
| 139 | // Test case 1: Basic module configuration |
| 140 | basicModuleYaml := ` |
| 141 | Source: ./module.yaml |
| 142 | Properties: |
| 143 | Name: test |
| 144 | Overrides: |
| 145 | Resource1: |
| 146 | Properties: |
| 147 | Name: overridden |
| 148 | ` |
| 149 | basicConfig, err := template.ParseModuleConfig("BasicModule", |
| 150 | unmarshalYaml(t, basicModuleYaml)) |
| 151 | if err != nil { |
| 152 | t.Errorf("ParseModuleConfig failed: %v", err) |
| 153 | } |
| 154 | |
| 155 | if basicConfig.Name != "BasicModule" { |
| 156 | t.Errorf("Expected Name=BasicModule, got %s", basicConfig.Name) |
| 157 | } |
| 158 | if basicConfig.Source != "./module.yaml" { |
| 159 | t.Errorf("Expected Source=./module.yaml, got %s", basicConfig.Source) |
| 160 | } |
| 161 | if basicConfig.PropertiesNode == nil { |
| 162 | t.Errorf("Expected PropertiesNode to be non-nil") |
| 163 | } |
| 164 | if basicConfig.OverridesNode == nil { |
| 165 | t.Errorf("Expected OverridesNode to be non-nil") |
| 166 | } |
| 167 | |
| 168 | // Test case 2: Module with Map |
| 169 | mapModuleYaml := ` |
| 170 | Source: ./module.yaml |
| 171 | ForEach: !Ref MyList |
| 172 | Properties: |
| 173 | Name: test-${MapValue} |
| 174 | ` |
| 175 | mapConfig, err := template.ParseModuleConfig("MapModule", |
| 176 | unmarshalYaml(t, mapModuleYaml)) |
| 177 | if err != nil { |
| 178 | t.Errorf("ParseModuleConfig failed: %v", err) |
| 179 | } |
| 180 | |
| 181 | if mapConfig.Name != "MapModule" { |
| 182 | t.Errorf("Expected Name=MapModule, got %s", mapConfig.Name) |
| 183 | } |
| 184 | if mapConfig.Map == nil { |
| 185 | t.Errorf("Expected Map to be non-nil") |
| 186 | } |
| 187 | |
| 188 | // Test case 3: Invalid node type |
| 189 | invalidNodeYaml := `- not a mapping node` |
| 190 | _, err = template.ParseModuleConfig("InvalidModule", |
| 191 | unmarshalYaml(t, invalidNodeYaml)) |
| 192 | if err == nil { |
nothing calls this directly
no test coverage detected