### Run Unit Tests Source: https://github.com/aliyun/aliyun-log-go-sdk/blob/master/TESTING.md Execute all unit tests for the project. No environment variables are required as HTTP traffic is mocked. ```bash go test ./... ``` -------------------------------- ### Set Up Environment Variables for E2E Tests Source: https://github.com/aliyun/aliyun-log-go-sdk/blob/master/TESTING.md Configure necessary environment variables for running end-to-end tests. These variables provide credentials and endpoint information for Alibaba Cloud SLS. ```bash export LOG_TEST_ENDPOINT=cn-hangzhou.log.aliyuncs.com export LOG_TEST_ACCESS_KEY_ID=... export LOG_TEST_ACCESS_KEY_SECRET=... export LOG_TEST_PROJECT=my-test-project export LOG_TEST_LOGSTORE=my-test-logstore # Optional, depending on which suites you run: export LOG_TEST_REGION=cn-hangzhou export LOG_TEST_ROLE_ARN=acs:ram::... export LOG_TEST_CMK_ID=... export LOG_TEST_CMK_ENDPOINT=... export LOG_TEST_METRIC_STORE_NAME=... export LOG_TEST_STORE_VIEW_PROJECT=... ``` -------------------------------- ### Build Mocked Client for Unit Tests Source: https://github.com/aliyun/aliyun-log-go-sdk/blob/master/TESTING.md Create a mocked HTTP transport and client for unit tests. This allows testing HTTP interactions without making actual network calls. Use RegisterJSON or RegisterError to stub responses. ```go import ( "github.com/aliyun/aliyun-log-go-sdk/internal/testutil" "github.com/aliyun/aliyun-log-go-sdk/internal/testutil/clienthelper" ) transport := testutil.NewMockTransport() testutil.RegisterJSON(t, transport, "POST", `=~^https://.+\.example\.com/logstores/.+/shards/lb$`, 200, map[string]any{}, nil) client := clienthelper.NewMockedClient(transport) // ... call client.PutLogs / GetLogs / etc. ``` -------------------------------- ### Run E2E Tests Source: https://github.com/aliyun/aliyun-log-go-sdk/blob/master/TESTING.md Execute end-to-end tests after setting the required environment variables. Build with the 'e2e' tag. ```bash go test -tags=e2e ./... ``` -------------------------------- ### Skip E2E Tests if Endpoint Not Configured Source: https://github.com/aliyun/aliyun-log-go-sdk/blob/master/TESTING.md Conditionally skip E2E tests if the necessary LOG_TEST_* environment variables are not set. The testutil.RequireE2E function handles this by calling t.Skip. ```go func TestSomethingE2E(t *testing.T) { cfg := testutil.RequireE2E(t) // skips if LOG_TEST_* env is empty client := sls.CreateNormalInterface(cfg.Endpoint, cfg.AccessKeyID, cfg.AccessKeySecret, "") // ... } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.