github.com/qiniu/go-sdk/v7@v7.27.0/pili/stat_test.go (about)

     1  //go:build integration
     2  // +build integration
     3  
     4  package pili
     5  
     6  import (
     7  	"context"
     8  	"testing"
     9  
    10  	"github.com/stretchr/testify/assert"
    11  )
    12  
    13  func TestManager_GetStatUpflow(t *testing.T) {
    14  	if SkipTest() {
    15  		t.SkipNow()
    16  	}
    17  	ast := assert.New(t)
    18  	// test 未设置select,是否会默认
    19  	manager := NewManager(ManagerConfig{AccessKey: AccessKey, SecretKey: SecretKey})
    20  	_, err := manager.GetStatUpflow(context.Background(), GetStatUpflowRequest{
    21  		GetStatCommonRequest: GetStatCommonRequest{
    22  			Begin: "20210928",
    23  			End:   "20210930",
    24  			G:     "hour",
    25  		},
    26  		Where: map[string][]string{"hub": {TestHub}, "area": {"!cn", "!hk"}},
    27  	})
    28  	ast.Nil(err)
    29  }
    30  
    31  func TestManager_GroupStatUpflow(t *testing.T) {
    32  	if SkipTest() {
    33  		t.SkipNow()
    34  	}
    35  	ast := assert.New(t)
    36  	manager := NewManager(ManagerConfig{AccessKey: AccessKey, SecretKey: SecretKey})
    37  	_, err := manager.GroupStatUpflow(context.Background(), GroupStatUpflowRequest{
    38  		GetStatCommonRequest: GetStatCommonRequest{
    39  			Begin: "20210928",
    40  			End:   "20210930",
    41  			G:     "hour",
    42  		},
    43  		Select: []string{"flow"},
    44  		Where:  map[string][]string{"hub": {TestHub}},
    45  		Group:  "hub",
    46  	})
    47  	ast.Nil(err)
    48  
    49  	// test group设置
    50  	_, err = manager.GroupStatUpflow(context.Background(), GroupStatUpflowRequest{
    51  		GetStatCommonRequest: GetStatCommonRequest{
    52  			Begin: "20210928",
    53  			End:   "20210930",
    54  			G:     "hour",
    55  		},
    56  		Where: map[string][]string{"hub": {TestHub}},
    57  		Group: "test",
    58  	})
    59  	ast.NotNil(err)
    60  }
    61  
    62  func TestManager_GetStatDownflow(t *testing.T) {
    63  	if SkipTest() {
    64  		t.SkipNow()
    65  	}
    66  	ast := assert.New(t)
    67  	manager := NewManager(ManagerConfig{AccessKey: AccessKey, SecretKey: SecretKey})
    68  	_, err := manager.GetStatDownflow(context.Background(), GetStatDownflowRequest{
    69  		GetStatCommonRequest: GetStatCommonRequest{
    70  			Begin: "20210928",
    71  			End:   "20210930",
    72  			G:     "day",
    73  		},
    74  		Select: []string{"flow"},
    75  		Where:  map[string][]string{"hub": {TestHub}},
    76  	})
    77  	ast.Nil(err)
    78  }
    79  
    80  func TestManager_GroupStatDownflow(t *testing.T) {
    81  	if SkipTest() {
    82  		t.SkipNow()
    83  	}
    84  	ast := assert.New(t)
    85  	manager := NewManager(ManagerConfig{AccessKey: AccessKey, SecretKey: SecretKey})
    86  	_, err := manager.GroupStatDownflow(context.Background(), GroupStatDownflowRequest{
    87  		GetStatCommonRequest: GetStatCommonRequest{
    88  			Begin: "20210928",
    89  			End:   "20210930",
    90  			G:     "day",
    91  		},
    92  		Select: []string{"flow"},
    93  		Where:  map[string][]string{"hub": {TestHub}},
    94  		Group:  "area",
    95  	})
    96  	ast.Nil(err)
    97  }
    98  
    99  func TestManager_GetStatCodec(t *testing.T) {
   100  	if SkipTest() {
   101  		t.SkipNow()
   102  	}
   103  	ast := assert.New(t)
   104  	manager := NewManager(ManagerConfig{AccessKey: AccessKey, SecretKey: SecretKey})
   105  	_, err := manager.GetStatCodec(context.Background(), GetStatCodecRequest{
   106  		GetStatCommonRequest: GetStatCommonRequest{
   107  			Begin: "20210928",
   108  			End:   "20210930",
   109  			G:     "day",
   110  		},
   111  		Select: []string{"duration"},
   112  		Where:  map[string][]string{"hub": {TestHub}, "profile": {"480p", "720p"}},
   113  	})
   114  	ast.Nil(err)
   115  
   116  	// test where Validate
   117  	_, err = manager.GetStatCodec(context.Background(), GetStatCodecRequest{
   118  		GetStatCommonRequest: GetStatCommonRequest{
   119  			Begin: "20210928",
   120  			End:   "20210930",
   121  			G:     "day",
   122  		},
   123  		Select: []string{"duration"},
   124  		Where:  map[string][]string{"testWhere": {TestHub}},
   125  	})
   126  	ast.NotNil(err)
   127  
   128  	// test select Validate
   129  	_, err = manager.GetStatCodec(context.Background(), GetStatCodecRequest{
   130  		GetStatCommonRequest: GetStatCommonRequest{
   131  			Begin: "20210928",
   132  			End:   "20210930",
   133  			G:     "day",
   134  		},
   135  		Select: []string{"count"},
   136  		Where:  map[string][]string{},
   137  	})
   138  	ast.NotNil(err)
   139  }
   140  
   141  func TestManager_GroupStatCodec(t *testing.T) {
   142  	if SkipTest() {
   143  		t.SkipNow()
   144  	}
   145  	ast := assert.New(t)
   146  	manager := NewManager(ManagerConfig{AccessKey: AccessKey, SecretKey: SecretKey})
   147  	_, err := manager.GroupStatCodec(context.Background(), GroupStatCodecRequest{
   148  		GetStatCommonRequest: GetStatCommonRequest{
   149  			Begin: "20210928",
   150  			End:   "20210930",
   151  			G:     "day",
   152  		},
   153  		Select: []string{"duration"},
   154  		Where:  map[string][]string{"hub": {"!" + TestHub}, "profile": {"480p", "720p"}},
   155  		Group:  "profile",
   156  	})
   157  	ast.Nil(err)
   158  }
   159  
   160  func TestManager_GetStatNrop(t *testing.T) {
   161  	if SkipTest() {
   162  		t.SkipNow()
   163  	}
   164  	ast := assert.New(t)
   165  	manager := NewManager(ManagerConfig{AccessKey: AccessKey, SecretKey: SecretKey})
   166  	_, err := manager.GetStatNrop(context.Background(), GetStatNropRequest{
   167  		GetStatCommonRequest: GetStatCommonRequest{
   168  			Begin: "20210928",
   169  			End:   "20210930",
   170  			G:     "5min",
   171  		},
   172  		Select: []string{"count"},
   173  		Where:  map[string][]string{"hub": {"!" + TestHub}, "assured": {"false"}},
   174  	})
   175  	ast.Nil(err)
   176  }
   177  
   178  func TestManager_GroupStatNrop(t *testing.T) {
   179  	if SkipTest() {
   180  		t.SkipNow()
   181  	}
   182  	ast := assert.New(t)
   183  	manager := NewManager(ManagerConfig{AccessKey: AccessKey, SecretKey: SecretKey})
   184  	_, err := manager.GroupStatNrop(context.Background(), GroupStatNropRequest{
   185  		GetStatCommonRequest: GetStatCommonRequest{
   186  			Begin: "20210928",
   187  			End:   "20210930",
   188  			G:     "5min",
   189  		},
   190  		Select: []string{"count"},
   191  		Where:  map[string][]string{"hub": {"!" + TestHub}, "assured": {"false", "true"}},
   192  		Group:  "assured",
   193  	})
   194  	ast.Nil(err)
   195  }
   196  
   197  func TestManager_GetStatCaster(t *testing.T) {
   198  	if SkipTest() {
   199  		t.SkipNow()
   200  	}
   201  	ast := assert.New(t)
   202  	manager := NewManager(ManagerConfig{AccessKey: AccessKey, SecretKey: SecretKey})
   203  	_, err := manager.GetStatCaster(context.Background(), GetStatCasterRequest{
   204  		GetStatCommonRequest: GetStatCommonRequest{
   205  			Begin: "20210928",
   206  			End:   "20210930",
   207  			G:     "day",
   208  		},
   209  		Select: []string{"upflow", "downflow", "duration"},
   210  		Where:  map[string][]string{"resolution": {"!480p"}},
   211  	})
   212  	ast.Nil(err)
   213  }
   214  
   215  func TestManager_GroupStatCaster(t *testing.T) {
   216  	if SkipTest() {
   217  		t.SkipNow()
   218  	}
   219  	ast := assert.New(t)
   220  	manager := NewManager(ManagerConfig{AccessKey: AccessKey, SecretKey: SecretKey})
   221  	_, err := manager.GroupStatCaster(context.Background(), GroupStatCasterRequest{
   222  		GetStatCommonRequest: GetStatCommonRequest{
   223  			Begin: "20210928",
   224  			End:   "20210930",
   225  			G:     "day",
   226  		},
   227  		Select: []string{"upflow", "downflow", "duration"},
   228  		Where:  map[string][]string{"resolution": {"!480p"}},
   229  		Group:  "resolution",
   230  	})
   231  	ast.Nil(err)
   232  }
   233  
   234  func TestManager_GetStatPub(t *testing.T) {
   235  	if SkipTest() {
   236  		t.SkipNow()
   237  	}
   238  	ast := assert.New(t)
   239  	manager := NewManager(ManagerConfig{AccessKey: AccessKey, SecretKey: SecretKey})
   240  	_, err := manager.GetStatPub(context.Background(), GetStatPubRequest{
   241  		GetStatCommonRequest: GetStatCommonRequest{
   242  			Begin: "20210928",
   243  			End:   "20210930",
   244  			G:     "hour",
   245  		},
   246  		Select: []string{"duration"},
   247  		Where:  map[string][]string{},
   248  	})
   249  	ast.Nil(err)
   250  }
   251  
   252  func TestManager_GroupStatPub(t *testing.T) {
   253  	if SkipTest() {
   254  		t.SkipNow()
   255  	}
   256  	ast := assert.New(t)
   257  	manager := NewManager(ManagerConfig{AccessKey: AccessKey, SecretKey: SecretKey})
   258  	_, err := manager.GroupStatPub(context.Background(), GroupStatPubRequest{
   259  		GetStatCommonRequest: GetStatCommonRequest{
   260  			Begin: "20210928",
   261  			End:   "20210930",
   262  			G:     "hour",
   263  		},
   264  		Select: []string{"duration"},
   265  		Where:  map[string][]string{},
   266  		Group:  "tp",
   267  	})
   268  	ast.Nil(err)
   269  }
   270  
   271  func TestForm(t *testing.T) {
   272  	if SkipTest() {
   273  		t.SkipNow()
   274  	}
   275  	ast := assert.New(t)
   276  	req := GroupStatUpflowRequest{
   277  		GetStatCommonRequest: GetStatCommonRequest{
   278  			Begin: "20210928",
   279  			End:   "20210930",
   280  			G:     "hour",
   281  		},
   282  		Where:  map[string][]string{"hub": {TestHub, "test1", "test2"}, "area": {"cn", "hk"}},
   283  		Group:  "group1",
   284  		Select: []string{"flow", "flow1"},
   285  	}
   286  	res := Form(req)
   287  	ast.Equal([]string{"20210928"}, res["begin"])
   288  	ast.Equal([]string{"20210930"}, res["end"])
   289  	ast.Equal([]string{"group1"}, res["group"])
   290  	ast.Equal([]string{TestHub, "test1", "test2"}, res["$hub"])
   291  	ast.Equal([]string{"cn", "hk"}, res["$area"])
   292  	ast.Equal([]string{"flow", "flow1"}, res["select"])
   293  }