Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
GreatDiscovery committed Apr 2, 2024
2 parents 4e23fe0 + 35f88c9 commit 1654157
Show file tree
Hide file tree
Showing 9 changed files with 578 additions and 0 deletions.
23 changes: 23 additions & 0 deletions test/basic/collection/set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,26 @@ func TestSetFrame(t *testing.T) {
fmt.Println(all)
fmt.Println(all.Contains("cooking"))
}

func TestSetDifference(t *testing.T) {
// Create a string-based set of required classes.
set1 := mapset.NewSet[string]()
set1.Add("cooking")
set1.Add("english")
set1.Add("math")
set1.Add("biology")

set2 := mapset.NewSet[string]()
set2.Add("cooking")
set2.Add("english")
set2.Add("math")
set2.Add("biology")
set2.Add("diff1")
set2.Add("diff2")

difference := set2.Difference(set1)
fmt.Println(difference)
slice := difference.ToSlice()
fmt.Println(slice)
fmt.Println(difference.Cardinality())
}
35 changes: 35 additions & 0 deletions test/basic/sort_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package main

import (
"fmt"
"sort"
"strings"
"testing"
)

func TestSortByFunc(t *testing.T) {

s1 := []string{"xx-1-0", "xx-2-1", "xx-51-0", "xx-51-1", "xx-3-1", "xx-3-0"}
fmt.Println("before sort =", s1)
sortSlice(s1)
fmt.Println("after sort =", s1)
}

func sortSlice(s1 []string) []string {
sort.Slice(s1, func(i, j int) bool {
split1 := strings.Split(s1[i], "-")
split2 := strings.Split(s1[j], "-")
role1 := split1[len(split1)-1]
role2 := split2[len(split2)-1]
version1 := split1[len(split1)-2]
version2 := split2[len(split2)-2]
if role1 > role2 {
return true
}
if version1 < version2 {
return true
}
return false
})
return s1
}
27 changes: 27 additions & 0 deletions test/concurrent/ticker_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package concurrent

import (
"fmt"
"testing"
"time"
)

// 一般用于超时控制
func TestTicker(t *testing.T) {
ticker := time.NewTicker(time.Second)
defer ticker.Stop()
done := make(chan bool)
go func() {
time.Sleep(10 * time.Second)
done <- true
}()
for {
select {
case <-done:
fmt.Println("Done!")
return
case t := <-ticker.C:
fmt.Println("Current time: ", t)
}
}
}
85 changes: 85 additions & 0 deletions test/container/mount_info_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package container

import (
"encoding/json"
"fmt"
"golang.org/x/sys/unix"
"testing"
)

// Info reveals information about a particular mounted filesystem. This
// struct is populated from the content in the /proc/<pid>/mountinfo file.
type Info struct {
// ID is a unique identifier of the mount (may be reused after umount).
ID int

// Parent is the ID of the parent mount (or of self for the root
// of this mount namespace's mount tree).
Parent int

// Major and Minor are the major and the minor components of the Dev
// field of unix.Stat_t structure returned by unix.*Stat calls for
// files on this filesystem.
Major, Minor int

// Root is the pathname of the directory in the filesystem which forms
// the root of this mount.
Root string

// Mountpoint is the pathname of the mount point relative to the
// process's root directory.
Mountpoint string

// Options is a comma-separated list of mount options.
Options string

// Optional are zero or more fields of the form "tag[:value]",
// separated by a space. Currently, the possible optional fields are
// "shared", "master", "propagate_from", and "unbindable". For more
// information, see mount_namespaces(7) Linux man page.
Optional string

// FSType is the filesystem type in the form "type[.subtype]".
FSType string

// Source is filesystem-specific information, or "none".
Source string

// VFSOptions is a comma-separated list of superblock options.
VFSOptions string
}

func (i *Info) String() string {
marshal, _ := json.Marshal(i)
return string(marshal)
}

func TestGetMountInfo(t *testing.T) {
count, err := unix.Getfsstat(nil, unix.MNT_WAIT)
if err != nil {
panic(err)
}

entries := make([]unix.Statfs_t, count)
_, err = unix.Getfsstat(entries, unix.MNT_WAIT)
if err != nil {
panic(err)
}

var out []*Info
for _, entry := range entries {
mountinfo := getMountinfo(&entry)
out = append(out, mountinfo)
}
for _, info := range out {
fmt.Printf("out=%+v\n", info)
}
}

func getMountinfo(entry *unix.Statfs_t) *Info {
return &Info{
Mountpoint: unix.ByteSliceToString(entry.Mntonname[:]),
FSType: unix.ByteSliceToString(entry.Fstypename[:]),
Source: unix.ByteSliceToString(entry.Mntfromname[:]),
}
}
18 changes: 18 additions & 0 deletions test/framework/grpc/hello/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
### grpcurl 工具

参考:https://chai2010.cn/advanced-go-programming-book/ch4-rpc/ch4-08-grpcurl.html


1. 安装grpcul工具
```shell
$ go get github.com/fullstorydev/grpcurl
$ go install github.com/fullstorydev/grpcurl/cmd/grpcurl
```
2. 查看服务列表
```shell
$ grpcurl -plaintext localhost:50051 list
HelloService.HelloService
grpc.reflection.v1alpha.ServerReflection

```
2.
Loading

0 comments on commit 1654157

Please sign in to comment.