@@ -228,10 +228,12 @@ func TestSaveConfig(t *testing.T) {
228
228
testhelpers .AssertNoError (t , test .config .Save ())
229
229
230
230
// test expected files
231
- for fileName , expectedContent := range test .expectedFiles {
231
+ for fileName := range test .expectedFiles {
232
+ expectedContent , err := test .config .HumanConfig ()
233
+ testhelpers .AssertNoError (t , err )
232
234
content , err := ioutil .ReadFile (filepath .Join (dir , fileName ))
233
235
testhelpers .AssertNoError (t , err )
234
- testhelpers .Equals (t , expectedContent , " \n " + string (content ))
236
+ testhelpers .Equals (t , expectedContent , string (content ))
235
237
}
236
238
237
239
})
@@ -580,3 +582,162 @@ func z(value Zone) *Zone {
580
582
func b (value bool ) * bool {
581
583
return & value
582
584
}
585
+
586
+ func TestConfig_ConfigFile (t * testing.T ) {
587
+
588
+ type testCase struct {
589
+ config * Config
590
+ result string
591
+ }
592
+
593
+ run := func (c * testCase ) func (t * testing.T ) {
594
+ return func (t * testing.T ) {
595
+ config , err := c .config .HumanConfig ()
596
+ testhelpers .AssertNoError (t , err )
597
+ testhelpers .Equals (t , c .result , config )
598
+ }
599
+ }
600
+
601
+ t .Run ("empty" , run (& testCase {
602
+ config : & Config {},
603
+ result : `# Scaleway configuration file
604
+
605
+ # You need an access key and a secret key to connect to Scaleway API.
606
+ # Generate your token at the following address: https://console.scaleway.com/account/credentials
607
+
608
+ # An access key is a secret key identifier.
609
+ # access_key: SCW11111111111111111
610
+
611
+ # The secret key is the value that can be used to authenticate against the API (the value used in X-Auth-Token HTTP-header).
612
+ # The secret key MUST stay secret and not given to anyone or published online.
613
+ # secret_key: 11111111-1111-1111-1111-111111111111
614
+
615
+ # Your organization ID is the identifier of your account inside Scaleway infrastructure.
616
+ # default_organization_id: 11111111-1111-1111-1111-111111111111
617
+
618
+ # A region is represented as a geographical area such as France (Paris) or the Netherlands (Amsterdam).
619
+ # It can contain multiple Availability Zones.
620
+ # Example of region: fr-par, nl-ams
621
+ # default_region: fr-par
622
+
623
+ # A region can be split into many availability zones (AZ).
624
+ # Latency between multiple AZ of the same region are low as they have a common network layer.
625
+ # Example of zones: fr-par-1, nl-ams-1
626
+ # default_zone: fr-par-1
627
+
628
+ # Scaleway CLI also supports profiles that will have a different set of credentials.
629
+ # You can define a CLI profile using the following syntax:
630
+
631
+ # myProfile:
632
+ # access_key: 11111111-1111-1111-1111-111111111111
633
+ # secret_key: 11111111-1111-1111-1111-111111111111
634
+ # organization_id: 11111111-1111-1111-1111-111111111111
635
+ # default_zone: fr-par-1
636
+ # default_region: fr-par
637
+ ` ,
638
+ }))
639
+
640
+ t .Run ("partial" , run (& testCase {
641
+ config : & Config {
642
+ Profile : Profile {
643
+ AccessKey : s (v2ValidAccessKey ),
644
+ }},
645
+ result : `# Scaleway configuration file
646
+
647
+ # You need an access key and a secret key to connect to Scaleway API.
648
+ # Generate your token at the following address: https://console.scaleway.com/account/credentials
649
+
650
+ # An access key is a secret key identifier.
651
+ access_key: ACCESS_KEY
652
+
653
+ # The secret key is the value that can be used to authenticate against the API (the value used in X-Auth-Token HTTP-header).
654
+ # The secret key MUST stay secret and not given to anyone or published online.
655
+ # secret_key: 11111111-1111-1111-1111-111111111111
656
+
657
+ # Your organization ID is the identifier of your account inside Scaleway infrastructure.
658
+ # default_organization_id: 11111111-1111-1111-1111-111111111111
659
+
660
+ # A region is represented as a geographical area such as France (Paris) or the Netherlands (Amsterdam).
661
+ # It can contain multiple Availability Zones.
662
+ # Example of region: fr-par, nl-ams
663
+ # default_region: fr-par
664
+
665
+ # A region can be split into many availability zones (AZ).
666
+ # Latency between multiple AZ of the same region are low as they have a common network layer.
667
+ # Example of zones: fr-par-1, nl-ams-1
668
+ # default_zone: fr-par-1
669
+
670
+ # Scaleway CLI also supports profiles that will have a different set of credentials.
671
+ # You can define a CLI profile using the following syntax:
672
+
673
+ # myProfile:
674
+ # access_key: 11111111-1111-1111-1111-111111111111
675
+ # secret_key: 11111111-1111-1111-1111-111111111111
676
+ # organization_id: 11111111-1111-1111-1111-111111111111
677
+ # default_zone: fr-par-1
678
+ # default_region: fr-par
679
+ ` ,
680
+ }))
681
+
682
+ t .Run ("full" , run (& testCase {
683
+ config : & Config {
684
+ Profile : Profile {
685
+ AccessKey : s (v2ValidAccessKey ),
686
+ SecretKey : s (v2ValidSecretKey ),
687
+ },
688
+ ActiveProfile : s (v2ValidProfile ),
689
+ Profiles : map [string ]* Profile {
690
+ "profile1" : {
691
+ AccessKey : s (v2ValidAccessKey2 ),
692
+ SecretKey : s (v2ValidSecretKey2 ),
693
+ },
694
+ "profile2" : {
695
+ AccessKey : s (v2ValidAccessKey2 ),
696
+ SecretKey : s (v2ValidSecretKey2 ),
697
+ },
698
+ },
699
+ },
700
+ result : `# Scaleway configuration file
701
+
702
+ # You need an access key and a secret key to connect to Scaleway API.
703
+ # Generate your token at the following address: https://console.scaleway.com/account/credentials
704
+
705
+ # An access key is a secret key identifier.
706
+ access_key: ACCESS_KEY
707
+
708
+ # The secret key is the value that can be used to authenticate against the API (the value used in X-Auth-Token HTTP-header).
709
+ # The secret key MUST stay secret and not given to anyone or published online.
710
+ secret_key: 7363616c-6577-6573-6862-6f7579616161
711
+
712
+ # Your organization ID is the identifier of your account inside Scaleway infrastructure.
713
+ # default_organization_id: 11111111-1111-1111-1111-111111111111
714
+
715
+ # A region is represented as a geographical area such as France (Paris) or the Netherlands (Amsterdam).
716
+ # It can contain multiple Availability Zones.
717
+ # Example of region: fr-par, nl-ams
718
+ # default_region: fr-par
719
+
720
+ # A region can be split into many availability zones (AZ).
721
+ # Latency between multiple AZ of the same region are low as they have a common network layer.
722
+ # Example of zones: fr-par-1, nl-ams-1
723
+ # default_zone: fr-par-1
724
+
725
+ # Scaleway CLI also supports profiles that will have a different set of credentials.
726
+ # You can define a CLI profile using the following syntax:
727
+
728
+ profile1:
729
+ access_key: ACCESS_KEY2
730
+ secret_key: 6f6e6574-6f72-756c-6c74-68656d616c6c
731
+ # default_organization_id: 11111111-1111-1111-1111-111111111111
732
+ # default_zone: fr-par-1
733
+ # default_region: fr-par
734
+
735
+ profile2:
736
+ access_key: ACCESS_KEY2
737
+ secret_key: 6f6e6574-6f72-756c-6c74-68656d616c6c
738
+ # default_organization_id: 11111111-1111-1111-1111-111111111111
739
+ # default_zone: fr-par-1
740
+ # default_region: fr-par
741
+ ` ,
742
+ }))
743
+ }
0 commit comments