Skip to content

Commit ebe03a0

Browse files
committed
add comments
1 parent cdd35d9 commit ebe03a0

File tree

8 files changed

+175
-46
lines changed

8 files changed

+175
-46
lines changed

cmd/function.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
Copyright 2025 API Testing Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
117
package cmd
218

319
import (

cmd/init.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
Copyright 2025 API Testing Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
117
package cmd
218

319
import (

cmd/jsonschema.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
Copyright 2025 API Testing Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
117
package cmd
218

319
import (

cmd/jsonschema_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
Copyright 2025 API Testing Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
117
package cmd_test
218

319
import (

cmd/mock-compose.go

Lines changed: 61 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,68 @@
1+
/*
2+
Copyright 2025 API Testing Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
117
package cmd
218

319
import (
4-
"github.com/linuxsuren/api-testing/pkg/mock"
5-
"github.com/spf13/cobra"
6-
"os"
7-
"os/signal"
8-
"syscall"
20+
"os"
21+
"os/signal"
22+
"syscall"
23+
24+
"github.com/linuxsuren/api-testing/pkg/mock"
25+
"github.com/spf13/cobra"
926
)
1027

1128
func createMockComposeCmd() (c *cobra.Command) {
12-
c = &cobra.Command{
13-
Use: "mock-compose",
14-
Short: "Mock a server",
15-
Args: cobra.ExactArgs(1),
16-
RunE: func(cmd *cobra.Command, args []string) (err error) {
17-
reader := mock.NewLocalFileReader(args[0])
18-
19-
var server *mock.Server
20-
if server, err = reader.Parse(); err != nil {
21-
return
22-
}
23-
24-
var subServers []mock.DynamicServer
25-
for _, proxy := range server.Proxies {
26-
subProxy := &mock.Server{
27-
Proxies: []mock.Proxy{proxy},
28-
}
29-
30-
subReader := mock.NewObjectReader(subProxy)
31-
subServer := mock.NewInMemoryServer(c.Context(), proxy.Port)
32-
if err = subServer.Start(subReader, proxy.Prefix); err != nil {
33-
return
34-
}
35-
subServers = append(subServers, subServer)
36-
}
37-
38-
clean := make(chan os.Signal, 1)
39-
signal.Notify(clean, syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP, syscall.SIGQUIT)
40-
select {
41-
case <-c.Context().Done():
42-
case <-clean:
43-
}
44-
for _, server := range subServers {
45-
server.Stop()
46-
}
47-
return
48-
},
49-
}
50-
return
29+
c = &cobra.Command{
30+
Use: "mock-compose",
31+
Short: "Mock multiple servers",
32+
Args: cobra.ExactArgs(1),
33+
RunE: func(cmd *cobra.Command, args []string) (err error) {
34+
reader := mock.NewLocalFileReader(args[0])
35+
36+
var server *mock.Server
37+
if server, err = reader.Parse(); err != nil {
38+
return
39+
}
40+
41+
var subServers []mock.DynamicServer
42+
for _, proxy := range server.Proxies {
43+
subProxy := &mock.Server{
44+
Proxies: []mock.Proxy{proxy},
45+
}
46+
47+
subReader := mock.NewObjectReader(subProxy)
48+
subServer := mock.NewInMemoryServer(c.Context(), proxy.Port)
49+
if err = subServer.Start(subReader, proxy.Prefix); err != nil {
50+
return
51+
}
52+
subServers = append(subServers, subServer)
53+
}
54+
55+
clean := make(chan os.Signal, 1)
56+
signal.Notify(clean, syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP, syscall.SIGQUIT)
57+
select {
58+
case <-c.Context().Done():
59+
case <-clean:
60+
}
61+
for _, server := range subServers {
62+
server.Stop()
63+
}
64+
return
65+
},
66+
}
67+
return
5168
}

cmd/root.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
Copyright 2025 API Testing Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
117
package cmd
218

319
import (

cmd/root_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
Copyright 2025 API Testing Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
117
package cmd
218

319
import (

cmd/service.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,29 @@
1-
// Package cmd provides a service command
1+
/*
2+
Copyright 2025 API Testing Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
217
package cmd
318

419
import (
520
"fmt"
6-
"github.com/linuxsuren/api-testing/pkg/util/home"
721
"io"
822
"os"
923
"strings"
1024

25+
"github.com/linuxsuren/api-testing/pkg/util/home"
26+
1127
_ "embed"
1228

1329
"github.com/linuxsuren/api-testing/pkg/version"

0 commit comments

Comments
 (0)