-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
926 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
apiserver/billing/odoostorage/odoo/odoo8/countries/countries.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package countries | ||
|
||
import ( | ||
"os" | ||
|
||
"sigs.k8s.io/yaml" | ||
) | ||
|
||
type Country struct { | ||
ID int `yaml:"id"` | ||
Code string `yaml:"code"` | ||
Name string `yaml:"name"` | ||
} | ||
|
||
func LoadCountryIDs(path string) (map[string]int, error) { | ||
r, err := os.ReadFile(path) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var countries []Country | ||
if err := yaml.UnmarshalStrict(r, &countries); err != nil { | ||
return nil, err | ||
} | ||
|
||
countryIDs := make(map[string]int, len(countries)) | ||
for _, c := range countries { | ||
countryIDs[c.Name] = c.ID | ||
} | ||
|
||
return countryIDs, nil | ||
} |
34 changes: 34 additions & 0 deletions
34
apiserver/billing/odoostorage/odoo/odoo8/countries/countries_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package countries | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func Test_LoadCountryIDs(t *testing.T) { | ||
const countriesYAML = ` | ||
- id: 1 | ||
code: BE | ||
name: Belgium | ||
- id: 5 | ||
code: FR | ||
name: France | ||
- id: 6 | ||
code: false # Seen in the export of the Odoo database | ||
name: Kabott | ||
` | ||
|
||
td := t.TempDir() | ||
p := td + "/countries.yaml" | ||
require.NoError(t, os.WriteFile(p, []byte(countriesYAML), 0644)) | ||
|
||
countryIDs, err := LoadCountryIDs(p) | ||
require.NoError(t, err) | ||
require.Equal(t, map[string]int{ | ||
"Belgium": 1, | ||
"France": 5, | ||
"Kabott": 6, | ||
}, countryIDs) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.